package com.sftz.framework.mvc.actionfilter;

import javax.servlet.http.HttpSession;

import org.nutz.mvc.ActionContext;
import org.nutz.mvc.ActionFilter;
import org.nutz.mvc.Mvcs;
import org.nutz.mvc.View;
import org.nutz.mvc.view.ServerRedirectView;

import com.sftz.framework.mvc.annotation.NoFilter;
import com.sftz.modules.admin.login.service.LoginService;

/**
 * 登录过滤器
 * @author 朱晓川
 *
 */
public class AdminLoginFilter implements ActionFilter {

	@Override
	public View match(ActionContext ac) {
		if (ac.getModule().getClass().isAnnotationPresent(NoFilter.class)) {
			return null;
		}

		HttpSession session = Mvcs.getHttpSession(false);
		if (session == null) {
			return new ServerRedirectView("/admin/login.html");
		}
		Object obj = session.getAttribute(LoginService.LOGINUSER);

		if (null == obj) {
			//TODO 前台登陆判断
			return new ServerRedirectView("/admin/login.html");
		}
		return null;
	}

}
